home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Treccani Italiana Di Scienze Lettere Ed Arti
/
[Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso
/
pc
/
data
/
xxi_appendice_dvd.swf
/
scripts
/
__Packages
/
CLoadingQueue.as
< prev
next >
Wrap
Text File
|
2007-11-08
|
5KB
|
132 lines
class CLoadingQueue extends mx.events.EventDispatcher
{
static var TYPE_MOVIECLIP = 0;
static var TYPE_XML = 1;
function CLoadingQueue(p_scope, p_slots)
{
super();
if(!p_scope)
{
p_scope = _root;
}
this._scope = p_scope;
this._queue = new Array();
this._isLoading = false;
this._usedSlots = 0;
this.setSlots(p_slots);
}
function setSlots(p_slots)
{
if(isNaN(p_slots) || p_slots < 1)
{
p_slots = 1;
}
this._maxSlots = p_slots;
}
function addMovie(p_mc, p_url, p_id, p_priority)
{
if(isNaN(p_priority))
{
p_priority = 5;
}
this._queue.push({type:CLoadingQueue.TYPE_MOVIECLIP,target:p_mc,url:p_url,isLoading:false,priority:p_priority,id:p_id});
}
function addXML(p_xml, p_url, p_id, p_priority)
{
if(isNaN(p_priority))
{
p_priority = 5;
}
this._queue.push({type:CLoadingQueue.TYPE_XML,target:p_xml,url:p_url,isLoading:false,priority:p_priority,id:p_id});
}
function start()
{
if(!this._isLoading)
{
this._isLoading = true;
this._scope.createEmptyMovieClip("LoadingQueueController",this._scope.getNextHighestDepth());
this._scope.LoadingQueueController.loadingInstance = this;
this._scope.LoadingQueueController.onEnterFrame = function()
{
this.loadingInstance.update();
};
}
}
function update()
{
if(this._isLoading)
{
if(this._queue.length > 0)
{
if(this._usedSlots < this._maxSlots)
{
var _loc6_ = undefined;
var _loc5_ = undefined;
var _loc2_ = 0;
while(_loc2_ < this._queue.length)
{
if(!this._queue[_loc2_].isLoading && (_loc5_ == undefined || this._queue[_loc2_].priority < _loc5_))
{
_loc6_ = _loc2_;
_loc5_ = this._queue[_loc2_].priority;
}
_loc2_ = _loc2_ + 1;
}
if(!isNaN(_loc6_))
{
switch(this._queue[_loc6_].type)
{
case CLoadingQueue.TYPE_MOVIECLIP:
this._queue[_loc6_].target.loadMovie(this._queue[_loc6_].url);
break;
case CLoadingQueue.TYPE_XML:
this._queue[_loc6_].target.load(this._queue[_loc6_].url);
}
this._queue[_loc6_].isLoading = true;
this._usedSlots = this._usedSlots + 1;
}
}
var _loc3_ = undefined;
var _loc8_ = undefined;
var _loc7_ = undefined;
var _loc4_ = undefined;
var _loc9_ = undefined;
_loc2_ = 0;
while(_loc2_ < this._queue.length)
{
if(this._queue[_loc2_].isLoading)
{
_loc3_ = this._queue[_loc2_].target;
_loc8_ = this._queue[_loc2_].id;
_loc7_ = _loc3_.getBytesLoaded();
_loc4_ = _loc3_.getBytesTotal();
_loc9_ = this._queue[_loc2_].type == CLoadingQueue.TYPE_MOVIECLIP && _loc3_._width > 0 || this._queue[_loc2_].type == CLoadingQueue.TYPE_XML && _loc3_.loaded;
if(_loc7_ >= _loc4_ && _loc4_ > 100 && _loc9_ || _loc3_ == undefined || _loc4_ == undefined)
{
this.dispatchEvent({type:"onLoadingQueueMessage",target:this,eventName:"loaded",eventArg:_loc8_});
this._queue.splice(_loc2_,1);
_loc2_ = _loc2_ - 1;
this._usedSlots = this._usedSlots - 1;
}
}
_loc2_ = _loc2_ + 1;
}
}
else
{
this.dispatchEvent({type:"onLoadingQueueMessage",target:this,eventName:"complete",eventArg:0});
this.stop();
}
}
}
function stop()
{
if(this._isLoading)
{
this.dispatchEvent({type:"onLoadingQueueMessage",target:this,eventName:"stopped",eventArg:0});
this._isLoading = false;
this._scope.LoadingQueueController.removeMovieClip();
}
}
}